import request from "@/utils/request";
import { updateInfo } from "./home";

//获取内部账号
export function getInsideList(listQuery) {
  const { current, pagesize, userId } = listQuery;
  return request(
    `/get/inside/user/list?current=${current}&pagesize=${pagesize}&userId=${userId}`
  );
}
//获取广告主账号
export function getAdvertiserList(listQuery) {
  const { current, pagesize, parentId } = listQuery;
  let tempUrl = !parentId
    ? `/get/advertiser/user/list?current=${current}&pagesize=${pagesize}`
    : `/get/advertiser/user/list?current=${current}&pagesize=${pagesize}&parentId=${parentId}`;
  return request.get(tempUrl);
}

//获取机构账号列表
export function getOrgannList(listQuery) {
  const { current, pagesize } = listQuery;
  return request.get(
    `/get/organization/list?current=${current}&pagesize=${pagesize}`
  );
}

//获取行业信息
export function getIndustryList() {
  return request(`/get/industry/list`);
}

//添加账号 addUser
// userInfo => Object 账号信息对象
// bool => boolean    true -> 内部账号  false -> 广告主账号

export function addUser(userInfo, bool) {
  let url = `/create/${bool ? "inside" : "advertiser"}/user/info`;
  return request.post(url, userInfo);
}

//添加客服账号
export function addCustomer(reqObj) {
  return request.post("/create/customer/service/info", reqObj);
}

//添加账号 addUser
// userInfo => Object 账号信息对象
export function addEditOrgan(userInfo, flag) {
  let url = `/${flag ? `create` : `update`}/organization/info`;
  return request.post(url, userInfo);
}

//编辑账号 editUser
// userInfo => Object 账号信息对象
// bool => boolean    true -> 内部账号  false -> 广告主账号
const updateAdverInfo = userInfo =>
  request.post("/update/advertiser/user/info", userInfo);
export function editUser(userInfo, bool) {
  let tempPost = bool ? updateInfo : updateAdverInfo;
  return tempPost(userInfo);
}

//锁定/解锁账号
// data => Object {"userId":1,"enable":1 // 0:锁定 1：解锁}
// bool => boolean    true -> 内部账号  false -> 广告主账号
export function enableUser(data, bool) {
  let url = `/enable/${bool ? "inside" : "advertiser"}/user`;
  return request.post(url, data);
}

//锁定/解锁账号
// data => Object {"userId":1,"enable":1 // 0:锁定 1：解锁}
export function enableOrg(data, bool) {
  let url = `/enable/organization`;
  return request.post(url, data);
}

//关键词开关
// data => Object {"userId":1,"enable":1 // 0:锁定 1：解锁}
export function enableSwitch(data) {
  let url = `/enable/show`;
  return request.post(url, data);
}

//客服优拨开关
// data => Object {"userId":1,"call":1 // 1:锁定 2：解锁}
export function enableCall(data) {
  let url = `/enable/call`;
  return request.post(url, data);
}
